<?php


namespace app\service;


use app\dao\RoomPriceDao;

class RoomPriceService
{
    private $RoomPriceDao;

    public function __construct()
    {
        $this->RoomPriceDao = new RoomPriceDao();
    }

//    public function getRoomPrice($id){
//        return $this->RoomPriceDao->customQuery()->filterById($id)->getOne();
//    }
//
//    public function getRoomPriceList($page , $limit){
//        return $this->RoomPriceDao->customQuery()->withRoom()->orderByRoomId()->getList($page , $limit);
//    }
//
    public function getRoomPriceByRoomId($room_id){
        return $this->RoomPriceDao->customQuery()->filterByRoomId($room_id)->getOne();
    }
//
//    public function editRoomPrice($id , $data){
//        $editData = [];
//        empty($data['now_price']) || $editData['now_price'] = $data['now_price'];
//        empty($data['start_time']) || $editData['start_time'] = $this->ConvertService->setTime($data['start_time']);
//        empty($data['end_time']) || $editData['end_time'] = $this->ConvertService->setTime($data['end_time']);
//        empty($data['room_id']) || $editData['room_id'] = $data['room_id'];
//
//        return $this->RoomPriceDao->edit($id , $editData);
//    }
//
//    public function delRoomPrice($id){
//        $this->RoomPriceDao->delete($id);
//    }
//
//    public function addRoomPrice($room_id , $now_price , $start_time = '1970-01-01' , $end_time = '2999-12-31'){
//        $saveData = [
//            'room_id' => $room_id,
//            'now_price' => $now_price,
//            'start_time' => $start_time,
//            'end_time' => $end_time
//        ];
//
//        return $this->RoomPriceDao->save($saveData);
//    }

    public function addRoomPrice($room_id , $price){
        return $this->RoomPriceDao->save([
           'room_id' => $room_id,
           'now_price' => $price
        ]);
    }

    public function editRoomPriceByRoomId($room_id , $price){
        $editData = [];
        empty($price) || $editData['now_price'] = $price;
        return $this->RoomPriceDao->edit($room_id , $editData);
    }

    public function delRoomPriceByRoomId($room_id){
        $model = $this->RoomPriceDao
            ->customQuery()
            ->filterByRoomId($room_id)
            ->getOne();
        $this->RoomPriceDao->delete($model->id);
    }
}